#!/usr/bin/python
# -*- coding: utf-8 -*-
#初始化t_profile_item表数据
import MySQLdb
import json
import sys

def getWarmDongList():
    levels = [0]
    reps = [1]
    actions = [3]
    durations = [20]
    map = []
    i = 1
    for level in levels:
        for rep in reps:
            for action in actions:
                for duration in durations:
                    keyDict = {'level':level,'rep':rep,'action':action,'duration':duration}
                    key = json.dumps(keyDict)
                    text = str(rep)+"组"+str(action)+"个动作"+str(duration)+"次"
                    #print key,text
                    map.append(('warm_dong','热身动',0,i,key,text))
                    i += 1
    return map
def getWarmJingList():
    levels = [0]
    reps = [1]
    actions = [6]
    durations = [8]
    map = []
    i = 1
    for level in levels:
        for rep in reps:
            for action in actions:
                for duration in durations:
                    keyDict = {'level':level,'rep':rep,'action':action,'duration':duration}
                    key = json.dumps(keyDict)
                    text = str(action)+"个动作"+str(duration)+"次"
                    #print key,text
                    map.append(('warm_jing','热身静',0,i,key,text))
                    i += 1
    return map
def getLaShenList():
    levels = [0]
    reps = [1]
    actions = [5]
    durations = [15]
    map = []
    i = 1
    for level in levels:
        for rep in reps:
            for action in actions:
                for duration in durations:
                    keyDict = {'level':level,'rep':rep,'action':action,'duration':duration}
                    key = json.dumps(keyDict)
                    text = str(action)+"个动作"+str(duration)+"次"
                    #print key,text
                    map.append(('stretch','拉伸',0,i,key,text))
                    i += 1
    return map

def getFuBuList():
    levels = [1,2,3,4,5]
    reps = [1,2]
    actions = [9]
    durations = [10,15,20,25,30]
    map = []
    i = 1
    for level in levels:
        for rep in reps:
            for action in actions:
                for duration in durations:
                    if(level>=4):
                        levelSub = level-1
                    else:
                        levelSub = level
                    if (duration >= (5+levelSub*5)):
                        keyDict = {'level':level,'rep':rep,'action':action,'duration':duration}
                        key = json.dumps(keyDict)
                        text = str(level)+"级难度"+str(rep)+"组"+str(duration)+"次"
                        #print key,text
                        map.append(('abdomen','力量',5,i,key,text))
                        i += 1
    return map

def getPowerList():
    levels = [1,2,3,4,5]
    reps = [1,2,3]
    actions = [3]
    durations = [10,15,20,25,30]
    map = []
    i = 1
    for level in levels:
        for rep in reps:
            for action in actions:
                for duration in durations:
                    if (duration >= (level*5+5)):
                        keyDict = {'level':level,'rep':rep,'action':action,'duration':duration}
                        key = json.dumps(keyDict)
                        text = str(level)+"级难度"+str(rep)+"组"+str(duration)+"次"
                        #print key,text
                        map.append(('arm','力量',1,i,key,text))
                        map.append(('shoulder','力量',2,i,key,text))
                        map.append(('back','力量',3,i,key,text))
                        map.append(('chest','力量',4,i,key,text))
                        map.append(('buttocks','力量',6,i,key,text))
                        map.append(('leg','力量',7,i,key,text))
                        i += 1
    return map

def getTabataList():
    levels = [0]
    reps = [1,2,3]
    actions = [5,6]
    durations = [20,25,30]
    map = []
    i = 1
    for level in levels:
        for rep in reps:
            for action in actions:
                for duration in durations:
                    keyDict = {'level':level,'rep':rep,'action':action,'duration':duration}
                    key = json.dumps(keyDict)
                    text = str(rep)+"组"+str(action)+"个动作"+str(duration)+"秒"
                    #print key,text
                    map.append(('tabata','tabata',0,i,key,text))
                    i += 1
    return map
if __name__ == "__main__":
    map = getWarmDongList()
    mapWarmJing = getWarmJingList()
    mapPower = getPowerList()
    mapFuBu = getFuBuList()
    mapTabata = getTabataList()
    mapLaShen = getLaShenList()
    map.extend(mapWarmJing)
    map.extend(mapPower)
    map.extend(mapFuBu)
    map.extend(mapTabata)
    map.extend(mapLaShen)
    conn = MySQLdb.connect(host="127.0.0.1",user="root",passwd="123456",port=3306)
    cur = conn.cursor()
    conn.select_db('knight')
    delSql = "truncate table t_profile_item"
    cur.execute(delSql)
    cur.executemany("insert into t_profile_item(`code`,`tag`,`part`,`key`,`value`,`text`) values(%s,%s,%s,%s,%s,%s)",map)
    conn.commit()
    cur.close()
    conn.close()
